/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.qsecurity.client.mvp;

import com.google.code.qsecurity.client.QClientFactory;
import com.google.code.qsecurity.client.activity.ForgottenPasswordActivity;
import com.google.code.qsecurity.client.activity.LoginActivity;
import com.google.code.qsecurity.client.activity.OfflineActivity;
import com.google.code.qsecurity.client.activity.OnlineActivity;
import com.google.code.qsecurity.client.activity.SignupActivity;
import com.google.code.qsecurity.client.activity.VerificationActivity;
import com.google.code.qsecurity.client.event.ForgottenPasswordEvent;
import com.google.code.qsecurity.client.event.LoginFormEvent;
import com.google.code.qsecurity.client.event.OfflineEvent;
import com.google.code.qsecurity.client.event.OnlineEvent;
import com.google.code.qsecurity.client.event.SecurityEvent;
import com.google.code.qsecurity.client.event.SignupFormEvent;
import com.google.code.qsecurity.client.event.VerificationFormEvent;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.place.shared.Place;
import com.google.inject.Inject;

/**
 * ActivityMapper associates each {@link Place} with its corresponding {@link Activity}.
 */
public class SecurityActivityMapper {

	/**
	 * Provided for {@link Activitie}s.
	 */
	private QClientFactory clientFactory;

	@Inject
	public SecurityActivityMapper(QClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}

	public Activity getActivity(SecurityEvent<?> event) {
		
		if (event instanceof OfflineEvent) {
			return new OfflineActivity((OfflineEvent) event, clientFactory);
		}

		if (event instanceof OnlineEvent) {
			return new OnlineActivity((OnlineEvent) event, clientFactory);
		}

		if (event instanceof LoginFormEvent) {
			return new LoginActivity((LoginFormEvent) event, clientFactory);
		}

		if (event instanceof SignupFormEvent) {
			return new SignupActivity((SignupFormEvent) event, clientFactory);
		}

		if (event instanceof VerificationFormEvent) {
			return new VerificationActivity((VerificationFormEvent) event, clientFactory);
		}

		if (event instanceof ForgottenPasswordEvent) {
			return new ForgottenPasswordActivity((ForgottenPasswordEvent) event, clientFactory);
		}
				
		return null;
	}

}
